<?php

abstract class Subject
{
    protected $observer_list = [];
    protected $action;

    //使用了具体的实现类ObserverStock，为了降低耦合，使用抽象类Observer代替ObserverStock
    public function attach(Observer $observer)
    {
        $this->observer_list[] = $observer;
    }

    public function detach(Observer $observer)
    {
        if ($key = array_search($observer, $this->observer_list)) {
            unset($this->observer_list[$key]);
        }
    }

    public function notify()
    {
        foreach ($this->observer_list as $observer) {
            $observer->update();
        }
    }

    public function getAction()
    {
        return $this->action;
    }

    public function setAction($value)
    {
        $this->action = $value;
    }
}